package 数论;

import java.util.Scanner;

public class 快速幂 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long b = scanner.nextLong();
        long p = scanner.nextLong();
        long k = scanner.nextLong();

        long temp = 1;
        while (p > 0) {
            if ((p & 1) == 1) {
                temp = (temp * b) % k;
            }
            b = (b * b) % k;
            p = p >> 1;
        }
        System.out.println(temp);
    }

}
